/*
 * $Id: PolisUser.java 28 2007-04-13 22:31:27Z aaron.day $
 */
package org.crazydays.core.data;


import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.*;

/**
 * Polis user class.
 */
@Entity
@SequenceGenerator(name = "POLIS_IDS", sequenceName = "polis_ids", allocationSize = 1)
@Table(name = "polis_user")
public class PolisUser
	extends PolisData
	implements Serializable
{
	/** serial version uid */
	public final static long serialVersionUID = "$Id: PolisUser.java 28 2007-04-13 22:31:27Z aaron.day $"
			.hashCode();

	/** username */
	@Basic
	@Column(unique = true)
	protected String username;

	/** password */
	@Basic
	@Column
	protected String password;

	/** email */
	@Basic
	@Column(nullable = true)
	protected String email;

	/** groups */
	@ManyToMany(targetEntity = org.crazydays.core.data.PolisGroup.class, cascade = {
			CascadeType.PERSIST, CascadeType.MERGE }, fetch = FetchType.LAZY)
	@JoinTable(name = "polis_user_group", joinColumns = { @JoinColumn(name = "polis_user") }, inverseJoinColumns = { @JoinColumn(name = "polis_group") })
	protected Set<PolisGroup> groups = new HashSet<PolisGroup>();

	/** owned groups */
	@OneToMany(mappedBy = "user", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
	protected Set<PolisGroup> ownedGroups = new HashSet<PolisGroup>();

	/** owned acls */
	@OneToMany(mappedBy = "user", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
	protected Set<PolisAcl> ownedAcls = new HashSet<PolisAcl>();

	/**
	 * Set username.
	 * 
	 * @param username Username
	 */
	public void setUsername(String username)
	{
		this.username = username;
	}

	/**
	 * Get username.
	 * 
	 * @return Username
	 */
	public String getUsername()
	{
		return username;
	}

	/**
	 * Set password.
	 * 
	 * @param password Password
	 */
	public void setPassword(String password)
	{
		this.password = password;
	}

	/**
	 * Get password.
	 * 
	 * @return Password
	 */
	public String getPassword()
	{
		return password;
	}

	/**
	 * Set email.
	 * 
	 * @param email Email
	 */
	public void setEmail(String email)
	{
		this.email = email;
	}

	/**
	 * Get email.
	 * 
	 * @return Email
	 */
	public String getEmail()
	{
		return email;
	}

	/**
	 * Set groups user is memeber.
	 * 
	 * @param Set of groups
	 */
	public void setGroups(Set<PolisGroup> groups)
	{
		this.groups = groups;
	}

	/**
	 * Get groups user is member.
	 * 
	 * @return Set of groups
	 */
	public Set<PolisGroup> getGroups()
	{
		return groups;
	}

	/**
	 * Set owned group.
	 * 
	 * @return Owned groups
	 */
	public void setOwnedGroups(Set<PolisGroup> ownedGroups)
	{
		this.ownedGroups = ownedGroups;
	}

	/**
	 * Get owned groups.
	 * 
	 * @return Owned groups
	 */
	public Set<PolisGroup> getOwnedGroups()
	{
		return ownedGroups;
	}

	/**
	 * Set owned acls.
	 * 
	 * @param ownedAcl Owned acls
	 */
	public void setOwnedAcls(Set<PolisAcl> ownedAcls)
	{
		this.ownedAcls = ownedAcls;
	}

	public Set<PolisAcl> getOwnedAcls()
	{
		return ownedAcls;
	}
}
